home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / SOUND.SWG / 0028_MIDI.pas < prev    next >
Pascal/Delphi Source File  |  1997-03-02  |  29KB  |  642 lines

  1. To get your copy of the 1.0 spec, send a $2 check to:
  2.  
  3. International Midi Association
  4. 5316 West 57th Street
  5. Los Angeles, CA 90056
  6. (415) 321-MIDI
  7.  
  8. Make your checks payable to the IMA.  BYW, the 1.0 spec is technically
  9. identical to the .06 spec, but the description has been re-written.
  10. Since the spec has been offically approved, there shouldn't be any
  11. problem with posting this summary of the .06 spec:
  12.  
  13.  
  14. [This document is Dave Oppenheim's current version of the MIDI file
  15. specification, as sent to those who have participated in its
  16. development.  The consensus seems to be to submit this to the MIDI
  17. Manufacturers' Association as version 1.0.  I apologize for any loss of
  18. clarity that might have occurred in the conversion from a Microsoft Word
  19. document to this pure text file.  I have removed some of the discussion
  20. about recent changes to the specification in order to keep the file size
  21. reasonable.--Doug Wyatt]
  22.  
  23. Standard MIDI Files 0.06        March 1, 1988
  24.  
  25.  
  26. 0  Introduction
  27.  
  28. This describes a proposed standard MIDI file format.  MIDI files contain
  29. one or more MIDI streams, with time information for each event.  Song,
  30. sequence, and track structures, tempo and time signature information,
  31. are all supported.  Track names and other descriptive information may be
  32. stored with the MIDI data.  This format supports multiple tracks and
  33. multiple sequences so that if the user of a program which supports
  34. multiple tracks intends to move a file to another one, this format can
  35. allow that to happen.
  36.  
  37. This spec defines the 8-bit binary data stream used in the file.  The
  38. data can be stored in a binary file, nibbleized, 7-bit-ized for
  39. efficient MIDI transmission, converted to Hex ASCII, or translated
  40. symbolically to a printable text file.  This spec addresses what's in
  41. the 8-bit stream.
  42.  
  43.  
  44. 1  Sequences, Tracks, Chunks:  File Block Structure
  45.  
  46. Sequence files are made up of chunks.  Each chunk has a 4-character type
  47. and a 32-bit length, which is the number of bytes in the chunk.  On the
  48. Macintosh, data is passed either in the data fork of a file, or on the
  49. Clipboard.  (The file type on the Macintosh for a file in this format
  50. will be "Midi".)  On any other computer, the data is simply the contents
  51. of the file.  This structure allows future chunk types to be designed
  52. which may easily be ignored if encountered by a program written before
  53. the chunk type is introduced.   Your programs should expect alien chunks
  54. and treat them as if they weren't there.
  55.  
  56. This proposal defines two types of chunks:  a header chunk and a track
  57. chunk.  A header chunk provides a minimal amount of information
  58. pertaining to the entire MIDI file.  A track chunk contains a sequential
  59. stream of MIDI data which may contain information for up to 16 MIDI
  60. channels.  The concepts of multiple tracks, multiple MIDI outputs,
  61. patterns, sequences, and songs may all be implemented using several
  62. track chunks.
  63.  
  64. A MIDI file always starts with a header chunk, and is followed by one or
  65. more track chunks.
  66.  
  67. MThd  <length of header data>
  68. <header data>
  69. MTrk  <length of track data>
  70. <track data>
  71. MTrk  <length of track data>
  72. <track data>
  73.  ...
  74.  
  75. Track Data Format (MTrk chunk type)
  76.  
  77. The MTrk chunk type is where actual song data is stored.  It is simply a
  78. stream of MIDI events (and non-MIDI events), preceded by delta-time
  79. values.
  80.  
  81. Some numbers in MTrk chunks are represented in a form called a variable-
  82. length quantity. These numbers are represented 7 bits per byte, most
  83. significant bits first.  All bytes except the last have bit 7 set, and
  84. the last byte has bit 7 clear.  If the number is between 0 and 127,  it
  85. is thus represented exactly as one byte.
  86.  
  87. Here are some examples of numbers represented as variable-length
  88. quantities:
  89.  
  90.         Number (hex)    Representation (hex)
  91.         00000000        00
  92.         00000040        40
  93.         0000007F        7F
  94.         00000080        81 00
  95.         00002000        C0 00
  96.         00003FFF        FF 7F
  97.         00004000        81 80 00
  98.         00100000        C0 80 00
  99.         001FFFFF        FF FF 7F
  100.         00200000        81 80 80 00
  101.         08000000        C0 80 80 00
  102.         0FFFFFFF        FF FF FF 7F
  103.  
  104.  
  105. The largest number which is allowed is 0FFFFFFF so that the variable-
  106. length representation must fit in 32 bits in a routine to write
  107. variable-length numbers.  Theoretically, larger numbers are possible,
  108. but 2 x 108 96ths of a beat at a fast tempo of 500 beats per minute is
  109. four days, long enough for any delta-time!
  110.  
  111. Here is the syntax of an MTrk chunk:
  112.  
  113. <track data> = <MTrk event>+
  114.  
  115. <MTrk event> = <delta-time> <event>
  116.  
  117. <delta-time> is stored as a variable-length quantity.  It represents the
  118. amount of time before the following event.  If the first event in a
  119. track occurs at the very beginning of a track, or if two events occur
  120. simultaneously, a delta-time of zero is used.  Delta-times are always
  121. present.  (Not storing delta-times of 0 requires at least two bytes for
  122. any other value, and most delta-times aren't zero.)  Delta-time is in
  123. some fraction of a beat (or a second, for recording a track with SMPTE
  124. times), as specified in the header chunk.
  125.  
  126. <event> = <MIDI event> | <sysex event> | <meta-event>
  127.  
  128. <MIDI event> is any MIDI channel message.  Running status is used:
  129. status bytes may be omitted after the first byte.  The first event in a
  130. file must specify status.  Delta-time is not  considered an event
  131. itself:  it is an integral part of the specification.  Notice that
  132. running status occurs across delta-times.
  133.  
  134. <meta-event> specifies non-MIDI information useful to this format or to
  135. sequencers, with this syntax:
  136.  
  137.         FF <type> <length> <bytes>
  138.  
  139. All meta-events begin with FF, then have an event type byte (which is
  140. always less than 128), and then have the length of the data stored as a
  141. variable-length quantity, and then the data itself.  If there is no
  142. data, the length is 0.  As with sysex events, running status is not
  143. allowed.  As with chunks, future meta-events may be designed which may
  144. not be known to existing programs, so programs must properly ignore
  145. meta-events which they do not recognize, and indeed, should expect to
  146. see them.  New for 0.06:  programs must never ignore the length of a
  147. meta-event which they do recognize, and they shouldn't be surprised if
  148. it's bigger than they expected.  If so, they must ignore everything past
  149. what they know about.  However, they must not add anything of their own
  150. to the end of a meta-event.
  151.  
  152. <sysex event> is used to specify a MIDI system exclusive message, or as
  153. an "escape" to specify any arbitrary bytes to be transmitted.
  154. Unfortunately, some synthesizer manufacturers specify that their system
  155. exclusive messages are to be transmitted as little packets.  Each packet
  156. is only part of an entire syntactical system exclusive message, but the
  157. times they are transmitted at are important.  Examples of this are the
  158. bytes sent in a CZ patch dump, or the FB-01's "system exclusive mode" in
  159. which microtonal data can be transmitted.  To be able to handle
  160. situations like these, two forms of  <sysex event> are provided:
  161.  
  162.         F0 <length> <bytes to be transmitted after F0>
  163.         F7 <length> <all bytes to be transmitted>
  164.  
  165. In both cases, <length> is stored as a variable-length quantity.  It is
  166. equal to the number of bytes following it, not including itself or the
  167. message type (F0 or F7), but all the bytes which follow, including any
  168. F7 at the end which is intended to be transmitted.  The first form, with
  169. the F0 code, is used for syntactically complete system exclusive
  170. messages, or the first packet an a series Q that is, messages in which
  171. the F0 should be transmitted.  The second form is used for the remainder
  172. of the packets within a syntactic sysex message, which do not begin with
  173. F0.  Of course, the F7 is not considered part of the system exclusive
  174. message.  Of course, just as in MIDI, running status is not allowed, in
  175. this case because the length is stored as a variable-length quantity
  176. which may or may not start with bit 7 set.
  177.  
  178. (New to 0.06)  A syntactic system exclusive message must always end with
  179. an F7, even if the real-life device didn't send one, so that you know
  180. when you've reached the end of an entire sysex message without looking
  181. ahead to the next event in the MIDI file.  This principle is repeated
  182. and illustrated in the paragraphs below.
  183.  
  184. The vast majority of system exclusive messages will just use the F0
  185. format.  For instance, the transmitted message F0 43 12 00 07 F7 would
  186. be stored in a MIDI file as F0 05 43 12 00 07 F7.  As mentioned above,
  187. it is required to include the F7 at the end so that the reader of the
  188. MIDI file knows that it has read the entire message.
  189.  
  190. For special situations when a single system exclusive message is split
  191. up, with parts of it being transmitted at different times, such as in a
  192. Casio CZ patch transfer, or the FB-01's "system exclusive mode", the F7
  193. form of sysex event is used for each packet except the first.  None of
  194. the packets would end with an F7 except the last one, which must end
  195. with an F7.  There also must not be any transmittable MIDI events in-
  196. between the packets of a multi-packet system exclusive message.  Here is
  197. an example:  suppose the bytes F0 43 12 00 were to be sent, followed by
  198. a 200-tick delay, followed by the bytes  43 12 00 43 12 00, followed by
  199. a 100-tick delay, followed by the bytes  43 12 00 F7, this would be in
  200. the MIDI File:
  201.  
  202.         F0 03 43 12 00
  203.         81 48                                   200-tick delta-time
  204.         F7 06 43 12 00 43 12 00
  205.         64                                      100-tick delta-time
  206.         F7 04 43 12 00 F7
  207.  
  208. The F7 event may also be used as an "escape" to transmit any bytes
  209. whatsoever, including real-time bytes, song pointer, or MIDI Time Code,
  210. which are not permitted normally in this specification.  No effort
  211. should be made to interpret the bytes used in this way.  Since a system
  212. exclusive message is not being transmitted, it is not necessary or
  213. appropriate to end the F7 event with an F7 in this case.
  214.  
  215.  
  216. 2    Header Chunk
  217.  
  218. The header chunk at the beginning of the file specifies some basic
  219. information about the data in the file.  The data section contains three
  220. 16-bit words, stored high byte first (of course).  Here's the syntax of
  221. the complete chunk:
  222.  
  223.         <chunk type> <length> <format> <ntrks> <division>
  224.  
  225. As described above, <chunk type> is the four ASCII characters 'MThd';
  226. <length> is a 32-bit representation of the number 6 (high byte first).
  227. The first word, format, specifies the overall organization of the file.
  228. Only three values of format are specified:
  229.  
  230.         0       the file contains a single multi-channel track
  231.         1       the file contains one or more simultaneous tracks (or MIDI
  232. outputs) of a sequence
  233.         2       the file contains one or more sequentially independent
  234. single-track patterns
  235.  
  236. The next word, ntrks, is the number of track chunks in the file.  The
  237. third word, division,  is the division of a quarter-note represented by
  238. the delta-times in the file.  (If division is negative, it represents
  239. the division of a second represented by the delta-times in the file, so
  240. that the track can represent events occurring in actual time instead of
  241. metrical time.  It is represented in the following way:  the upper byte
  242. is one of the four values -24, -25, -29, or -30, corresponding to the
  243. four standard SMPTE and MIDI time code formats, and represents the
  244. number of frames per second.  The second byte (stored positive) is the
  245. resolution within a frame:  typical values may be 4 (MIDI time code
  246. resolution), 8, 10, 80 (bit resolution), or 100.  This system allows
  247. exact specification of time-code-based tracks, but also allows
  248. millisecond-based tracks by specifying 25 frames/sec and a resolution of
  249. 40 units per frame.)
  250.  
  251. Format 0, that is, one multi-channel track, is the most interchangeable
  252. representation of data.  One application of MIDI files is a simple
  253. single-track player in a program which needs to make synthesizers make
  254. sounds, but which is primarily concerned with something else such as
  255. mixers or sound effect boxes.  It is very desirable to be able to
  256. produce such a format, even if your program is track-based, in order to
  257. work with these simple programs.  On the other hand, perhaps someone
  258. will write a format conversion from format 1 to format 0 which might be
  259. so easy to use in some setting that it would save you the trouble of
  260. putting it into your program.
  261.  
  262. Programs which support several simultaneous tracks should be able to
  263. save and read data in format 1, a vertically one-dimensional form, that
  264. is, as a collection of tracks.  Programs which support several
  265. independent patterns should be able to save and read data in format 2, a
  266. horizontally one-dimensional form.  Providing these minimum capabilities
  267. will ensure maximum interchangeability.
  268.  
  269. MIDI files can express tempo and time signature, and they have been
  270. chosen to do so for transferring tempo maps from one device to another.
  271. For a format 0 file, the tempo will be scattered through the track and
  272. the tempo map reader should ignore the intervening events; for a format
  273. 1 file, the tempo map must (starting in 0.04) be stored as the first
  274. track.  It is polite to a tempo map reader to offer your user the
  275. ability to make a format 0 file with just the tempo, unless you can use
  276. format 1.
  277.  
  278. All MIDI files should specify tempo and time signature.  If they don't,
  279. the time signature is assumed to be 4/4, and the tempo 120 beats per
  280. minute.  In format 0, these meta-events should occur at least at the
  281. beginning of the single multi-channel track.  In format 1, these meta-
  282. events should be contained in the first track.  In format 2, each of the
  283. temporally independent patterns should contain at least initial time
  284. signature and tempo information.
  285.  
  286. We may decide to define other format IDs to support other structures.  A
  287. program reading an unfamiliar format ID should return an error to the
  288. user rather than trying to read further.
  289.  
  290. 3    Meta-Events
  291.  
  292. A few meta-events are defined herein.  It is not required for every
  293. program to support every meta-event.  Meta-events initially defined
  294. include:
  295.  
  296. FF 00 02 ssss   Sequence Number
  297. This optional event, which must occur at the beginning of a track,
  298. before any nonzero delta-times, and before any transmittable MIDI
  299. events, specifies the number of a sequence.  The number in this track
  300. corresponds to the sequence number in the new Cue message discussed at
  301. the summer 1987 MMA meeting.  In a format 2 MIDI file, it is used to
  302. identify each "pattern" so that a "song" sequence using the Cue message
  303. to refer to the patterns.  If the ID numbers are omitted, the sequences'
  304. locations in order in the file are used as defaults.  In a format 0 or 1
  305. MIDI file, which only contain one sequence, this number should be
  306. contained in the first (or only) track.  If transfer of several
  307. multitrack sequences is required, this must be done as a group of format
  308. 1 files, each with a different sequence number.
  309.  
  310. FF 01 len text  Text Event
  311. Any amount of text describing anything.  It is a good idea to put a text
  312. event right at the beginning of a track, with the name of the track, a
  313. description of its intended orchestration, and any other information
  314. which the user wants to put there.  Text events may also occur at other
  315. times in a track, to be used as lyrics, or descriptions of cue points.
  316. The text in this event should be printable ASCII characters for maximum
  317. interchange.  However, other character codes using the high-order bit
  318. may be used for interchange of files between different programs on the
  319. same computer which supports an extended character set.  Programs on a
  320. computer which does not support non-ASCII characters should ignore those
  321. characters.
  322.  
  323. (New for 0.06 ).  Meta event types 01 through 0F are reserved for
  324. various types of text events, each of which meets the specification of
  325. text events(above) but is used for a different purpose:
  326.  
  327. FF 02 len text  Copyright Notice
  328. Contains a copyright notice as printable ASCII text.  The notice should
  329. contain the characters (C), the year of the copyright, and the owner of
  330. the copyright.  If several pieces of music are in the same MIDI file,
  331. all of the copyright notices should be placed together in this event so
  332. that it will be at the beginning of the file.  This event should be the
  333. first event in the first track chunk, at time 0.
  334.  
  335.  
  336. FF 03 len text  Sequence/Track Name
  337. If in a format 0 track, or the first track in a format 1 file, the name
  338. of the sequence.  Otherwise, the name of the track.
  339.  
  340. FF 04 len text  Instrument Name
  341. A description of the type of instrumentation to be used in that track.
  342. May be used with the MIDI Prefix meta-event to specify which MIDI
  343. channel the description applies to, or the channel may be specified as
  344. text in the event itself.
  345.  
  346. FF 05 len text  Lyric
  347. A lyric to be sung.  Generally, each syllable will be a separate lyric
  348. event which begins at the event's time.
  349.  
  350. FF 06 len text  Marker
  351. Normally in a format 0 track, or the first track in a format 1 file.
  352. The name of that point in the sequence, such as a rehearsal letter or
  353. section name ("First Verse", etc.).
  354.  
  355.  
  356. FF 07 len text  Cue Point
  357. A description of something happening on a film or video screen or stage
  358. at that point in the musical score ("Car crashes into house", "curtain
  359. opens", "she slaps his face", etc.)
  360.  
  361. FF 2F 00        End of Track
  362. This event is not optional.  It is included so that an exact ending
  363. point may be specified for the track, so that it has an exact length,
  364. which is necessary for tracks which are looped or concatenated.
  365.  
  366. FF 51 03 tttttt         Set Tempo, in microseconds per MIDI quarter-note
  367. This event indicates a tempo change.  Another way of putting
  368. "microseconds per quarter-note" is "24ths of a microsecond per MIDI
  369. clock".  Representing tempos as time per beat instead of beat per time
  370. allows absolutely exact long-term synchronization with a time-based sync
  371. protocol such as SMPTE time code or MIDI time code.  This amount of
  372. accuracy provided by this tempo resolution allows a four-minute piece at
  373. 120 beats per minute to be accurate within 500 usec at the end of the
  374. piece.  Ideally, these events should only occur where MIDI clocks would
  375. be located Q this convention is intended to guarantee, or at least
  376. increase the likelihood, of compatibility with other synchronization
  377. devices so that a time signature/tempo map stored in this format may
  378. easily be transferred to another device.
  379.  
  380. FF 54 05 hr mn se fr ff SMPTE Offset  (New in 0.06 - SMPTE Format
  381. specification)
  382. This event, if present, designates the SMPTE time at which the track
  383. chunk is supposed to start.  It should be present at the beginning of
  384. the track, that is, before any nonzero delta-times, and before any
  385. transmittable MIDI events.  The hour must be encoded with the SMPTE
  386. format, just as it is in MIDI Time Code.  In a format 1 file, the SMPTE
  387. Offset must be stored with the tempo map, and has no meaning in any of
  388. the other tracks.  The ff field contains fractional frames, in 100ths of
  389. a frame, even in SMPTE-based tracks which specify a different frame
  390. subdivision for delta-times.
  391.  
  392. FF 58 04 nn dd cc bb    Time Signature
  393. The time signature is expressed as four numbers.  nn and dd represent
  394. the numerator and denominator of the time signature as it would be
  395. notated.  The denominator is a negative power of two:  2 represents a
  396. quarter-note, 3 represents an eighth-note, etc.  The cc parameter
  397. expresses the number of MIDI clocks in a metronome click.  The bb
  398. parameter expresses the number of notated 32nd-notes in a MIDI quarter-
  399. note (24 MIDI Clocks).  This was added because there are already
  400. multiple programs which allow the user to specify that what MIDI thinks
  401. of as a quarter-note (24 clocks) is to be notated as, or related to in
  402. terms of, something else.
  403.  
  404. Therefore, the complete event for 6/8 time, where the metronome clicks
  405. every three eighth-notes, but there are 24 clocks per quarter-note, 72
  406. to the bar, would be (in hex):
  407.  
  408.         FF 58 04 06 03 24 08
  409.  
  410. That is, 6/8 time (8 is 2 to the 3rd power, so this is 06 03), 32 MIDI
  411. clocks per dotted-quarter (24 hex!), and eight notated 32nd-notes per
  412. MIDI quarter note.
  413.  
  414. FF 59 02 sf mi  Key Signature
  415.         sf = -7:  7 flats
  416.         sf = -1:  1 flat
  417.         sf = 0:  key of C
  418.         sf = 1:  1 sharp
  419.         sf = 7: 7 sharps
  420.  
  421.         mi = 0:  major key
  422.         mi = 1:  minor key
  423.  
  424. FF 7F len data  Sequencer-Specific Meta-Event
  425.  
  426.         Special requirements for particular sequencers may use this
  427. event type:  the first byte or bytes of data is a manufacturer ID.
  428. However, as this is an interchange format, growth of the spec proper is
  429. preferred to use of this event type.  This type of event may be used by
  430. a sequencer which elects to use this as its only file format;
  431. sequencers with their established feature-specific formats should
  432. probably stick to the standard features when using this format.
  433.  
  434. 4   Program Fragments and Example MIDI Files
  435.  
  436. Here are some of the routines to read and write variable-length numbers
  437. in MIDI Files.  These routines are in C, and use getc and putc, which
  438. read and write single 8-bit characters from/to the files infile and
  439. outfile.
  440.  
  441. WriteVarLen (value)
  442. register long value;
  443. {
  444.         register long buffer;
  445.  
  446.         buffer = value & 0x7f;
  447.         while ((value >>= 7) > 0)
  448.         {
  449.                 buffer <<= 8;
  450.                 buffer |= 0x80;
  451.                 buffer += (value & 0x7f);
  452.         }
  453.  
  454.         while (TRUE)
  455.         {
  456.                 putc(buffer,outfile);
  457.                 if (buffer & 0x80)
  458.                         buffer >>= 8;
  459.                 else
  460.                         break;
  461.         }
  462. }
  463.  
  464. doubleword ReadVarLen ()
  465. {
  466.         register doubleword value;
  467.         register byte c;
  468.  
  469.         if ((value = getc(infile)) & 0x80)
  470.         {
  471.                 value &= 0x7f;
  472.                 do
  473.                 {
  474.                         value = (value << 7) + ((c = getc(infile)) & 0x7f);
  475.                 } while (c & 0x80);
  476.         }
  477.         return (value);
  478. }
  479.  
  480. As an example, MIDI Files for the following excerpt are shown below.
  481. First, a format 0 file is shown, with all information intermingled;
  482. then, a format 1 file is shown with all data separated into four tracks:
  483. one for tempo and time signature, and three for the notes.  A resolution
  484. of 96 "ticks" per quarter note is used.  A time signature of 4/4 and a
  485. tempo of 120, though implied, are explicitly stated.
  486.  
  487.  
  488.  
  489.  
  490. The contents of the MIDI stream represented by this example are broken
  491. down here:
  492.  
  493. Delta Time(decimal)  Event Code (hex)   Other Bytes (decimal)
  494.         Comment
  495.         0       FF 58   04 04 02 24 08  4 bytes: 4/4 time, 24 MIDI
  496. clocks/click,
  497.                                 8 32nd notes/24 MIDI clocks
  498.         0       FF 51   03 500000       3 bytes: 500,000 5sec per quarter-note
  499.         0       C0      5       Ch. 1, Program Change 5
  500.         0       C0      5       Ch. 1, Program Change 5
  501.         0       C1      46      Ch. 2, Program Change 46
  502.         0       C2      70      Ch. 3, Program Change 70
  503.         0       92      48  96  Ch. 3 Note On C2, forte
  504.         0       92      60  96  Ch. 3 Note On C3, forte
  505.         96      91      67  64  Ch. 2 Note On G3, mezzo-forte
  506.         96      90      76  32  Ch. 1 Note On E4, piano
  507.         192     82      48  64  Ch. 3 Note Off C2, standard
  508.         0       82      60  64  Ch. 3 Note Off C3, standard
  509.         0       81      67  64  Ch. 2 Note Off G3, standard
  510.         0       80      76  64  Ch. 1 Note Off E4, standard
  511.         0       FF 2F   00      Track End
  512.  
  513. The entire format 0 MIDI file contents in hex follow.  First, the header
  514. chunk:
  515.  
  516.                 4D 54 68 64     MThd
  517.                 00 00 00 06     chunk length
  518.                 00 00   format 0
  519.                 00 01   one track
  520.                 00 60   96 per quarter-note
  521.  
  522. Then, the track chunk.  Its header, followed by the events (notice that
  523. running status is used in places):
  524.  
  525.                 4D 54 72 6B     MTrk
  526.                 00 00 00 3B     chunk length (59)
  527.  
  528.         Delta-time      Event   Comments
  529.         00      FF 58 04 04 02 18 08    time signature
  530.         00      FF 51 03 07 A1 20       tempo
  531.         00      C0 05
  532.         00      C1 2E
  533.         00      C2 46
  534.         00      92 30 60
  535.         00      3C 60   running status
  536.         60      91 43 40
  537.         60      90 4C 20
  538.         81 40   82 30 40        two-byte delta-time
  539.         00      3C 40   running status
  540.         00      81 43 40
  541.         00      80 4C 40
  542.         00      FF 2F 00        end of track
  543.  
  544. A format 1 representation of the file is slightly different.  Its header
  545. chunk:
  546.  
  547.                 4D 54 68 64     MThd
  548.                 00 00 00 06     chunk length
  549.                 00 01   format 1
  550.                 00 04   four tracks
  551.                 00 60   96 per quarter-note
  552.  
  553. First, the track chunk for the time signature/tempo track.  Its header,
  554. followed by the events:
  555.  
  556.                 4D 54 72 6B     MTrk
  557.                 00 00 00 14     chunk length (20)
  558.  
  559.         Delta-time      Event   Comments
  560.         00      FF 58 04 04 02 18 08    time signature
  561.         00      FF 51 03 07 A1 20       tempo
  562.         83 00   FF 2F 00        end of track
  563.  
  564. Then, the track chunk for the first music track.  The MIDI convention
  565. for note on/off running status is used in this example:
  566.  
  567.                 4D 54 72 6B     MTrk
  568.                 00 00 00 10     chunk length (16)
  569.  
  570.         Delta-time      Event   Comments
  571.         00      C0 05
  572.         81 40   90 4C 20
  573.         81 40   4C 00   Running status: note on, vel = 0
  574.         00      FF 2F 00        end of track
  575.  
  576. Then, the track chunk for the second music track:
  577.  
  578.                 4D 54 72 6B     MTrk
  579.                 00 00 00 0F     chunk length (15)
  580.  
  581.         Delta-time      Event   Comments
  582.         00      C1 2E
  583.         60      91 43 40
  584.         82 20   43 00   running status
  585.         00      FF 2F 00        end of track
  586.  
  587. Then, the track chunk for the third music track:
  588.  
  589.                 4D 54 72 6B     MTrk
  590.                 00 00 00 15     chunk length (21)
  591.  
  592.         Delta-time      Event   Comments
  593.         00      C2 46
  594.         00      92 30 60
  595.         00      3C 60   running status
  596.         83 00   30 00   two-byte delta-time, running status
  597.         00      3C 00   running status
  598.         00      FF 2F 00        end of track
  599.  
  600. 5   MIDI Transmission of MIDI Files
  601.  
  602. Since it is inconvenient to exchange disks between different computers,
  603. and since many computers which will use this format will have a MIDI
  604. interface anyway, MIDI seems like a perfect way to send these files from
  605. one computer to another.  And, while we're going through all the trouble
  606. to make a way of sending MIDI Files, it would be nice if they could send
  607. any files (like sampled sound files, text files, etc.)
  608.  
  609. Goals
  610. The transmission protocol for MIDI files should be reasonably efficient,
  611. should support fast transmission for computers which are capable of it,
  612. and slower transmission for less powerful ones.  It should not be
  613. impossible to convert a MIDI File to or from an arbitrary internal
  614. representation on the fly as it is transmitted, but, as long as it is
  615. not too difficult, it is very desirable to use a generic method so that
  616. any file type could be accommodated.
  617.  
  618. To make the protocol efficient, the MIDI transmission of these files
  619. will take groups of seven 8-bit bytes and transmit them as eight 7-bit
  620. MIDI data bytes.  This is certainly in the spirit of the rest of this
  621. format (keep it small, because it's not that hard to do).  To
  622. accommodate a wide range of transmission speeds, files will be
  623. transmitted in packets with acknowledge -- this allows data to be stored
  624. to disk as it is received.  If the sender does not receive a response
  625. from a reader in a certain amount of time, it can assume an open-loop
  626. situation, and then just continue.
  627.  
  628. The last edition of MIDI Files contained a specialized protocol for
  629. sending just MIDI Files.  To meet a deadline, unfortunately I don't have
  630. time right now to propose a new generalized protocol.  This will be done
  631. within the next couple of months.  I would welcome any proposals anyone
  632. else has, and would direct your attention to the proposal from Ralph
  633. Muha of Kurzweil, available in a recent MMA bulletin, and also directly
  634. from him.
  635.  
  636.  
  637. --
  638. Michael S. Czeiszperger         | "The only good composer is a dead composer"
  639. Systems Analyst                 | Snail: 2015 Neil Avenue         (614)
  640. The Ohio State University       |        Columbus, OH 43210          292-
  641. ARPA:czei@accelerator.eng.ohio-state.edu  PAN:CZEI                     0161
  642.